﻿package plugin.roleN.controller
{
    import com.core.*;
    import com.sh.game.display.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.roleN.model.*;
    import pluginfw.nio.*;
    import uiresource.roleui.*;
    import view.*;
    import view.mornExtends.*;
    import view.uilt.*;
    import vo.*;

    public class FeiShenCtrl extends FeishengUI
    {
        private var cfg_fly:Object;
        private var userFly:Array;
        private var userdata:Object;
        private var showatt:Array;
        private var showdata:Object;
        private var showdata1:Object;
        private var showarr1:Array;
        private var _mask:Sprite;
        private var flydata:Object;
        private var fsarr:Array;
        private var cfglevel:Object;
        private var storeID:Array;
        private var cfgstore:Object;
        private var cfgitem:Object;
        private var qianMC:XMLMovieClip;
        public var cgMC:XMLMovieClip;

        public function FeiShenCtrl()
        {
            this.showatt = ["攻击", "防御", "血量", "准确", "闪避", "暴击"];
            this.storeID = [481, 482];
            return;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.roleui.FeiShenItemUI"] = FeiShenItemCtrl;
            loadUI("Feisheng.xml");
            this.fsarr = [];
            var _loc_1:int = 1;
            while (_loc_1 <= 6)
            {
                
                this.fsarr.push(this["fs" + _loc_1] as FeiShenItemCtrl);
                _loc_1++;
            }
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_1:Object = null;
            super.initializeView();
            this.cfg_fly = ConfigDictionary.data.feishen;
            this.cfglevel = ConfigDictionary.data.level;
            this.cfgstore = ConfigDictionary.data.storeNew;
            this.cfgitem = ConfigDictionary.data.item;
            this.userdata = ModelProxy.getValue("data", "user");
            this._mask = new Sprite();
            this._mask.graphics.clear();
            this._mask.graphics.beginFill(16777215, 1);
            this._mask.graphics.drawRect(0, 0, 137, 14);
            this._mask.x = xiuwei.x;
            this._mask.y = xiuwei.y;
            this.addChild(this._mask);
            xiuwei.mask = this._mask;
            rigth_box.visible = false;
            this.userFly = [];
            for each (_loc_1 in this.cfg_fly)
            {
                
                if (_loc_1.type == this.userdata.career)
                {
                    this.userFly.push(_loc_1);
                }
            }
            this.addEvent();
            return;
        }// end function

        public function init(param1:Object) : void
        {
            var _loc_3:String = null;
            var _loc_4:String = null;
            if (param1 == null)
            {
                param1 = ModelProxy.getValue("feishen", "init");
            }
            if (!this.qianMC)
            {
                this.loadmc();
            }
            this.flydata = param1;
            this.userdata = ModelProxy.getValue("data", "user");
            if (this.userdata.level < 100)
            {
                return;
            }
            this.showLevel(this.userdata.level, lv, lv1, lv3);
            this.showLevel((this.userdata.level - 1), lv4, lv5, lv6);
            if (this.userdata.level < 101)
            {
                btn_duihuan.disabled = true;
            }
            else
            {
                btn_duihuan.disabled = false;
            }
            if (this.cfglevel[(this.userdata.level - 1)])
            {
                txt_exp.text = int(int(this.cfglevel[(this.userdata.level - 1)]) / 10000) + "";
            }
            var _loc_2:* = UserData.getBagData("flyuppower");
            if (this.userdata.rein >= this.userFly[param1.fslevel].needRein)
            {
                _loc_3 = "<font color=\'#31cf08\'>" + this.userFly[param1.fslevel].needRein + "转</font>";
            }
            else
            {
                _loc_3 = "<font color=\'#ff0000\'>" + this.userFly[param1.fslevel].needRein + "转</font>";
            }
            if (this.userdata.level >= this.userFly[param1.fslevel].needLevel)
            {
                _loc_4 = "<font color=\'#31cf08\'>" + this.userFly[param1.fslevel].needLevel + "级</font>";
            }
            else
            {
                _loc_4 = "<font color=\'#ff0000\'>" + this.userFly[param1.fslevel].needLevel + "级</font>";
            }
            needlv.text = "角色等级需求：" + _loc_4;
            needrein.text = "角色转生需求：" + _loc_3;
            xiuweizhi.text = _loc_2 + "/" + this.userFly[param1.fslevel].needEnergy;
            xiaohaoqian.text = "" + this.userFly[param1.fslevel].needGold;
            this._mask.width = _loc_2 / int(this.userFly[param1.fslevel].needEnergy) * 137 > 137 ? (137) : (_loc_2 / int(this.userFly[param1.fslevel].needEnergy) * 137);
            if (param1.fslevel == 36)
            {
                xiulianBtn.disabled = true;
            }
            this.showdata = this.userFly[param1.fslevel];
            this.showdata1 = this.userFly[(param1.fslevel + 1)];
            this.showxian(param1.fslevel);
            this.initList();
            return;
        }// end function

        public function playMC() : void
        {
            if (this.cgMC == null)
            {
                this.cgMC = XMLMcManager.instance.getPluginMc("role", "flycg");
                if (this.cgMC)
                {
                    this.cgMC.mouseChildren = false;
                    this.cgMC.mouseEnabled = false;
                    this.cgMC.x = -65;
                    this.cgMC.y = -5;
                    this.cgMC.visible = false;
                    this.cgMC.interval = 1000 / 8;
                    this.cgMC.play();
                    this.addChild(this.cgMC);
                    this.shengjinguanwei();
                }
            }
            else
            {
                this.shengjinguanwei();
            }
            return;
        }// end function

        public function shengjinguanwei() : void
        {
            if (this.cgMC)
            {
                this.cgMC.visible = true;
                this.cgMC.playFromTo(-1, (this.cgMC.totalFrame - 1), new Handler(this.doEnd1));
            }
            return;
        }// end function

        private function doEnd1() : void
        {
            this.cgMC.visible = false;
            this.cgMC.stop();
            return;
        }// end function

        private function loadmc() : void
        {
            this.qianMC = XMLMcManager.instance.getPluginMc("role", "flyqq");
            if (this.qianMC)
            {
                this.qianMC.blendMode = BlendMode.ADD;
                this.qianMC.mouseChildren = false;
                this.qianMC.mouseEnabled = false;
                this.qianMC.x = 40;
                this.qianMC.y = 120;
                this.qianMC.play();
                this.addChildAt(this.qianMC, 2);
            }
            return;
        }// end function

        public function xwEXP(param1:int) : void
        {
            xiuweizhi.text = param1 + "/" + this.userFly[this.flydata.fslevel].needEnergy;
            this._mask.width = param1 / int(this.userFly[this.flydata.fslevel].needEnergy) * 137 > 137 ? (137) : (param1 / int(this.userFly[this.flydata.fslevel].needEnergy) * 137);
            return;
        }// end function

        private function showxian(param1:int) : void
        {
            var _loc_2:int = 0;
            var _loc_6:int = 0;
            var _loc_7:Array = null;
            var _loc_8:String = null;
            var _loc_9:int = 0;
            var _loc_10:Array = null;
            var _loc_11:String = null;
            var _loc_12:int = 0;
            var _loc_13:String = null;
            var _loc_14:String = null;
            var _loc_15:String = null;
            if (param1 <= 6)
            {
                _loc_2 = param1;
                if (_loc_2 <= 0)
                {
                    ceng.visible = false;
                }
                else
                {
                    ceng.visible = true;
                    ceng.url = "cs2_zhuansheng/fs" + _loc_2 + ".png";
                }
            }
            else
            {
                _loc_2 = param1 % 6;
                if (_loc_2 == 1)
                {
                    _loc_6 = 0;
                    while (_loc_6 < 6)
                    {
                        
                        this.fsarr[_loc_6].isMc = false;
                        _loc_6++;
                    }
                }
                else if (_loc_2 == 0)
                {
                    _loc_2 = 6;
                }
                ceng.url = "cs2_zhuansheng/fs" + _loc_2 + ".png";
            }
            xian.url = "cs2_zhuansheng/xian" + this.shenMxian(param1)[1] + ".png";
            var _loc_3:* = String(this.shenMxian(param1)[0]);
            var _loc_4:* = UserData.getBagData("flyuppower");
            var _loc_5:int = 0;
            while (_loc_5 < 6)
            {
                
                if (_loc_5 < _loc_2)
                {
                    this.fsarr[_loc_5].isMc = true;
                    _loc_7 = this.showshuxin(param1 - _loc_2 + _loc_5 + 1);
                    _loc_8 = "";
                    _loc_9 = 0;
                    while (_loc_9 < _loc_7.length)
                    {
                        
                        _loc_8 = _loc_8 + (_loc_7[_loc_9] + "\n");
                        _loc_9++;
                    }
                    this.fsarr[_loc_5].data = "<font color=\'#ffd700\' size=\'14\'>" + _loc_3 + (_loc_5 + 1) + "层</font>\n\n<font color=\'#ffd700\' size=\'12\'>增加属性</font>\n\n" + _loc_8;
                }
                else
                {
                    _loc_10 = this.showshuxin(param1 - _loc_2 + _loc_5 + 1);
                    _loc_11 = "";
                    _loc_12 = 0;
                    while (_loc_12 < _loc_10.length)
                    {
                        
                        _loc_11 = _loc_11 + (_loc_10[_loc_12] + "\n");
                        _loc_12++;
                    }
                    if (this.userdata.rein >= this.userFly[param1 - _loc_2 + _loc_5].needRein)
                    {
                        _loc_13 = "#31cf08";
                    }
                    else
                    {
                        _loc_13 = "#ff0000";
                    }
                    if (this.userdata.level >= this.userFly[param1 - _loc_2 + _loc_5].needLevel)
                    {
                        _loc_15 = "#31cf08";
                    }
                    else
                    {
                        _loc_15 = "#31cf08";
                    }
                    if (_loc_4 >= this.userFly[param1 - _loc_2 + _loc_5].needEnergy)
                    {
                        _loc_14 = "#31cf08";
                    }
                    else
                    {
                        _loc_14 = "#ff0000";
                    }
                    _loc_11 = _loc_11 + ("<font color=\'#ffd700\'>升级条件\n需求转生：</font><font color=\'" + _loc_13 + "\'>" + this.userFly[param1 - _loc_2 + _loc_5].needRein + "转</font>\n<font color=\'#ffd700\'>需求等级：</font><font color=\'" + _loc_15 + "\'>" + this.userFly[param1 - _loc_2 + _loc_5].needLevel + "级</font>\n<font color=\'#ffd700\'>需要真气：</font><font color=\'" + _loc_14 + "\'>" + this.userFly[param1 - _loc_2 + _loc_5].needEnergy + "</font>");
                    this.fsarr[_loc_5].isMc = false;
                    this.fsarr[_loc_5].data = "<font color=\'#ffd700\' size=\'14\'>" + _loc_3 + (_loc_5 + 1) + "层</font>\n\n<font color=\'#ffd700\' size=\'12\'>增加属性</font>\n\n" + _loc_11;
                }
                _loc_5++;
            }
            return;
        }// end function

        private function showshuxin(param1:int) : Array
        {
            var _loc_4:Object = null;
            var _loc_2:Array = [];
            var _loc_3:* = this.userFly[param1];
            if (param1 == 0)
            {
                _loc_4 = this.userFly[0];
            }
            else
            {
                _loc_4 = this.userFly[(param1 - 1)];
            }
            if (_loc_3.phyAtt > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>物攻:</font><font color=\'#53b436\'>" + (int(_loc_3.phyAtt) - int(_loc_4.phyAtt)) + " - " + (int(_loc_3.phyAttMax) - int(_loc_4.phyAttMax)) + "</font>");
            }
            if (_loc_3.magicAtt > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>魔攻:</font><font color=\'#53b436\'>" + (int(_loc_3.magicAtt) - int(_loc_4.magicAtt)) + " - " + (int(_loc_3.magicAttMax) - int(_loc_4.magicAttMax)) + "</font>");
            }
            if (_loc_3.taoAtt > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>道攻:</font><font color=\'#53b436\'>" + (int(_loc_3.taoAtt) - int(_loc_4.taoAtt)) + " - " + (int(_loc_3.taoAttMax) - int(_loc_4.taoAttMax)) + "</font>");
            }
            if (_loc_3.phyDef > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>物防:</font><font color=\'#53b436\'>" + (int(_loc_3.phyDef) - int(_loc_4.phyDef)) + " - " + (int(_loc_3.phyDefMax) - int(_loc_4.phyDefMax)) + "</font>");
            }
            if (_loc_3.magicDef > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>魔防:</font><font color=\'#53b436\'>" + (int(_loc_3.magicDef) - int(_loc_4.magicDef)) + " - " + (int(_loc_3.magicDefMax) - int(_loc_4.magicDefMax)) + "</font>");
            }
            if (_loc_3.hp > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>血量:</font><font color=\'#53b436\'>" + (int(_loc_3.hp) - int(_loc_4.hp)) + "%</font>");
            }
            if (_loc_3.accurate > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>准确:</font><font color=\'#53b436\'>" + (int(_loc_3.accurate) - int(_loc_4.accurate)) + "</font>");
            }
            if (_loc_3.dodge > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>闪避:</font><font color=\'#53b436\'>" + (int(_loc_3.dodge) - int(_loc_4.dodge)) + "</font>");
            }
            if (_loc_3.critRate > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>暴击:</font><font color=\'#53b436\'>" + (int(_loc_3.critRate) - int(_loc_4.critRate)) + "</font>");
            }
            if (_loc_3.pureatk > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>神圣:</font><font color=\'#53b436\'>" + (int(_loc_3.pureatk) - int(_loc_4.pureatk)) + "</font>");
            }
            if (_loc_3.neili > 0)
            {
                _loc_2.push("<font color=\'#ffd700\'>内力:</font><font color=\'#53b436\'>" + (int(_loc_3.neili) - int(_loc_4.neili)) + "</font>");
            }
            if (_loc_2.length > 6)
            {
                _loc_2.splice(6);
            }
            return _loc_2;
        }// end function

        private function shenMxian(param1:int) : Array
        {
            var _loc_3:int = 0;
            var _loc_2:String = "";
            var _loc_4:Array = [];
            if (param1 < 7)
            {
                _loc_2 = "一重";
                _loc_3 = 1;
            }
            else if (param1 < 13)
            {
                _loc_2 = "二重";
                _loc_3 = 2;
            }
            else if (param1 < 19)
            {
                _loc_3 = 3;
                _loc_2 = "三重";
            }
            else if (param1 < 25)
            {
                _loc_3 = 4;
                _loc_2 = "四重";
            }
            else if (param1 < 31)
            {
                _loc_3 = 5;
                _loc_2 = "五重";
            }
            else
            {
                _loc_3 = 6;
                _loc_2 = "六重";
            }
            var _loc_5:* = [_loc_2, _loc_3];
            _loc_4 = [_loc_2, _loc_3];
            return _loc_5;
        }// end function

        public function clearMC() : void
        {
            var _loc_1:int = 0;
            while (_loc_1 < 6)
            {
                
                this.fsarr[_loc_1].isMc = false;
                _loc_1++;
            }
            if (this.qianMC)
            {
                if (this.qianMC.parent)
                {
                    this.qianMC.parent.removeChild(this.qianMC);
                }
                this.qianMC.dispose();
                this.qianMC = null;
            }
            if (this.cgMC)
            {
                this.cgMC.dispose();
                if (this.cgMC.parent)
                {
                    this.cgMC.parent.removeChild(this.cgMC);
                }
                this.cgMC = null;
            }
            return;
        }// end function

        private function initList() : void
        {
            var _loc_1:Array = null;
            if (this.showdata)
            {
                _loc_1 = [];
                if (this.showdata.phyAtt)
                {
                    _loc_1.push({att:"物攻:", show:this.showdata.phyAtt + " - " + this.showdata.phyAttMax});
                }
                if (this.showdata.magicAtt)
                {
                    _loc_1.push({att:"魔攻:", show:this.showdata.magicAtt + " - " + this.showdata.magicAttMax});
                }
                if (this.showdata.taoAtt)
                {
                    _loc_1.push({att:"道攻:", show:this.showdata.taoAtt + " - " + this.showdata.taoAttMax});
                }
                if (this.showdata.phyDef)
                {
                    _loc_1.push({att:"物防:", show:this.showdata.phyDef + " - " + this.showdata.phyDefMax});
                }
                if (this.showdata.magicDef)
                {
                    _loc_1.push({att:"魔防:", show:this.showdata.magicDef + " - " + this.showdata.magicDefMax});
                }
                if (this.showdata.hp)
                {
                    _loc_1.push({att:"血量:", show:this.showdata.hp + "%"});
                }
                if (this.showdata.accurate)
                {
                    _loc_1.push({att:"准确:", show:this.showdata.accurate});
                }
                if (this.showdata.dodge)
                {
                    _loc_1.push({att:"闪避:", show:this.showdata.dodge});
                }
                if (this.showdata.critRate)
                {
                    _loc_1.push({att:"暴击:", show:this.showdata.critRate});
                }
                if (this.showdata.pureatk)
                {
                    _loc_1.push({att:"神圣:", show:this.showdata.pureatk});
                }
                if (this.showdata.neili)
                {
                    _loc_1.push({att:"内力:", show:this.showdata.neili});
                }
                if (_loc_1.length > 6)
                {
                    _loc_1.splice(6);
                }
                showlist.array = _loc_1;
            }
            if (this.showdata1)
            {
                this.showarr1 = [];
                if (int(this.showdata1.phyAttMax))
                {
                    this.showarr1.push({att:"物攻:", show:this.showdata1.phyAtt + " - " + this.showdata1.phyAttMax});
                }
                if (this.showdata1.magicAttMax)
                {
                    this.showarr1.push({att:"魔攻:", show:this.showdata1.magicAtt + " - " + this.showdata1.magicAttMax});
                }
                if (this.showdata1.taoAttMax)
                {
                    this.showarr1.push({att:"道攻:", show:this.showdata1.taoAtt + " - " + this.showdata1.taoAttMax});
                }
                if (this.showdata1.phyDef)
                {
                    this.showarr1.push({att:"物防:", show:this.showdata1.phyDef + " - " + this.showdata1.phyDefMax});
                }
                if (this.showdata1.magicDef)
                {
                    this.showarr1.push({att:"魔防:", show:this.showdata1.magicDef + " - " + this.showdata1.magicDefMax});
                }
                if (this.showdata1.hp)
                {
                    this.showarr1.push({att:"血量:", show:this.showdata1.hp + "%"});
                }
                if (this.showdata1.accurate)
                {
                    this.showarr1.push({att:"准确:", show:this.showdata1.accurate});
                }
                if (this.showdata1.dodge)
                {
                    this.showarr1.push({att:"闪避:", show:this.showdata1.dodge});
                }
                if (this.showdata1.critRate)
                {
                    this.showarr1.push({att:"暴击:", show:this.showdata1.critRate});
                }
                if (this.showdata1.pureatk)
                {
                    this.showarr1.push({att:"神圣:", show:this.showdata1.pureatk});
                }
                if (this.showdata1.neili)
                {
                    this.showarr1.push({att:"内力:", show:this.showdata1.neili});
                }
                if (this.showarr1.length > 6)
                {
                    this.showarr1.splice(6);
                }
            }
            return;
        }// end function

        private function addEvent() : void
        {
            closebtn.addEventListener(MouseEvent.CLICK, this.openRigth);
            txt_fb.addEventListener(MouseEvent.CLICK, this.openRigth);
            xiulianBtn.addEventListener(MouseEvent.CLICK, this.xuilian);
            showlist.renderHandler = new Handler(this.listhandler);
            btn_duihuan.addEventListener(MouseEvent.CLICK, this.duihuan);
            qianwangLabel.addEventListener(MouseEvent.CLICK, this.chongzhi);
            daojilist.renderHandler = new Handler(this.renderHandler);
            daojilist.array = this.storeID;
            return;
        }// end function

        private function renderHandler(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:FlashItem = null;
            var _loc_6:Label = null;
            var _loc_7:Label = null;
            var _loc_8:Button = null;
            if (param2 < this.storeID.length)
            {
                _loc_3 = this.cfgstore[this.storeID[param2]];
                _loc_4 = ItemObject.create(this.cfgitem[_loc_3.itemid]);
                _loc_5 = param1.getChildByName("fitem") as FlashItem;
                _loc_5.data = _loc_4;
                _loc_6 = param1.getChildByName("txt_name") as Label;
                _loc_6.text = _loc_4.name;
                _loc_7 = param1.getChildByName("labelmoney") as Label;
                _loc_7.text = _loc_3.nowprice;
                _loc_8 = param1.getChildByName("btn_shiyong") as Button;
                _loc_8.clickHandler = new Handler(this.gobuy, [_loc_3]);
            }
            return;
        }// end function

        private function gobuy(param1:Object) : void
        {
            var _loc_2:* = UserData.getBagData("money");
            if (_loc_2 < param1.nowprice)
            {
                ModelProxy.change("movetips", "error", "元宝不足，无法购买该道具！");
                return;
            }
            DialogMgr.instance.open(AppDialog.SC_BUY, {storeId:param1.id});
            return;
        }// end function

        protected function chongzhi(event:MouseEvent) : void
        {
            if (!ItemUilt.canpay)
            {
                ModelProxy.change("movetips", "error", "功能尚未开放，敬请期待");
                return;
            }
            ExternalInterface.call("topay");
            return;
        }// end function

        protected function duihuan(event:MouseEvent) : void
        {
            PluginManager.instance.sendToBufferServer("feishen", CMDFly.LFY_GetEXP, new Output());
            return;
        }// end function

        private function listhandler(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Label = null;
            var _loc_5:Label = null;
            var _loc_6:Label = null;
            var _loc_7:Image = null;
            if (param2 < showlist.array.length)
            {
                _loc_3 = showlist.array[param2];
                _loc_4 = param1.getChildByName("txt1") as Label;
                _loc_4.text = _loc_3.att;
                _loc_5 = param1.getChildByName("txt2") as Label;
                _loc_5.text = _loc_3.show;
                _loc_6 = param1.getChildByName("txt3") as Label;
                _loc_7 = param1.getChildByName("up") as Image;
                if (this.showdata1)
                {
                    var _loc_8:Boolean = true;
                    _loc_6.visible = true;
                    _loc_7.visible = _loc_8;
                    if (this.showarr1[param2])
                    {
                        _loc_6.text = this.showarr1[param2].show;
                    }
                    else
                    {
                        _loc_6.text = "";
                    }
                }
                else
                {
                    var _loc_8:Boolean = false;
                    _loc_6.visible = false;
                    _loc_7.visible = _loc_8;
                }
            }
            return;
        }// end function

        private function showLevel(param1:int, param2:Image, param3:Image, param4:Image) : void
        {
            if (param1 < 100)
            {
                param4.visible = false;
                param2.url = "png.common." + int(param1 / 10);
                param3.url = "png.common." + param1 % 10;
            }
            else
            {
                param4.visible = true;
                param2.url = "png.common." + String(param1).charAt(0);
                param3.url = "png.common." + String(param1).charAt(1);
                param4.url = "png.common." + String(param1).charAt(2);
            }
            return;
        }// end function

        protected function xuilian(event:MouseEvent) : void
        {
            PluginManager.instance.sendToBufferServer("feishen", CMDFly.SEED_FLY, new Output());
            return;
        }// end function

        protected function openRigth(event:MouseEvent) : void
        {
            rigth_box.visible = !rigth_box.visible;
            return;
        }// end function

    }
}
